<template>
	<el-drawer :title="titleMap[mode]" v-model="visible" :size="600" append-to-body destroy-on-close @closed="$emit('closed')">
		<el-container>
			<el-main class="nopadding">
				<el-scrollbar>
					<el-row class="drawer-table">
						<el-col :span="24">
							<el-form :model="form" :rules="rules" :disabled="mode==='show'" ref="dialogForm" label-width="80px">
								<el-form-item label="支付历史 -- 升级放到mongoDB" prop="paymentHistoryId">
									<el-input v-model="form.paymentHistoryId" placeholder="请输入支付历史 -- 升级放到mongoDB" clearable></el-input>
								</el-form-item>
								<el-form-item label="部门 或 店铺" prop="departmentId">
									<el-input v-model="form.departmentId" placeholder="请输入部门 或 店铺" clearable></el-input>
								</el-form-item>
								<el-form-item label="支付方式id" prop="paymentMethodId">
									<el-input v-model="form.paymentMethodId" placeholder="请输入支付方式id" clearable></el-input>
								</el-form-item>
								<el-form-item label="账户,方法,金额" prop="payMessage">
									<el-input v-model="form.payMessage" placeholder="请输入账户,方法,金额" clearable></el-input>
								</el-form-item>
								<el-form-item label="订单编码" prop="orderNo">
									<el-input v-model="form.orderNo" placeholder="请输入订单编码" clearable></el-input>
								</el-form-item>
								<el-form-item label="支付金额" prop="amount">
									<el-input v-model="form.amount" placeholder="请输入支付金额" clearable></el-input>
								</el-form-item>
								<el-form-item label="支付报错回款信息" prop="errorMessage">
									<el-input v-model="form.errorMessage" placeholder="请输入支付报错回款信息" clearable></el-input>
								</el-form-item>
								<el-form-item label="支付报错状态码" prop="errorCode">
									<el-input v-model="form.errorCode" placeholder="请输入支付报错状态码" clearable></el-input>
								</el-form-item>
								<el-form-item label="支付状态返回信息" prop="receiveData">
									<el-input v-model="form.receiveData" placeholder="请输入支付状态返回信息" clearable></el-input>
								</el-form-item>
								<el-form-item label="收款账号编码" prop="skNumb">
									<el-input v-model="form.skNumb" placeholder="请输入收款账号编码" clearable></el-input>
								</el-form-item>
								<el-form-item label="平台 1手机 2pc电脑 3线下支付" prop="isFrom">
									<el-input v-model="form.isFrom" placeholder="请输入平台 1手机 2pc电脑 3线下支付" clearable></el-input>
								</el-form-item>
								<el-form-item label="支付时间" prop="createTime">
									<el-input v-model="form.createTime" placeholder="请输入支付时间" clearable></el-input>
								</el-form-item>
								<el-form-item label="支付客户端ip" prop="remoteIp">
									<el-input v-model="form.remoteIp" placeholder="请输入支付客户端ip" clearable></el-input>
								</el-form-item>
								<el-form-item label="支付状态 1成功 0失败 2已退款" prop="flag">
									<el-input v-model="form.flag" placeholder="请输入支付状态 1成功 0失败 2已退款" clearable></el-input>
								</el-form-item>
                            </el-form>
						</el-col>
					</el-row>
				</el-scrollbar>
			</el-main>
			<el-footer>
				<el-button v-if="mode!=='show'" :loading="isSaveing" @click="submit()" type="primary" size="small">保 存</el-button>
				<el-button size="small" @click="visible=false">取 消</el-button>
			</el-footer>
		</el-container>
	</el-drawer>
</template>
<script>
	import paymentAPI from '@/api/payment/paymentHistory';
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增',
					edit: '编辑',
					mode: '在线支付历史记录,非在线支付，不会保存到该模块'
				},
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					paymentHistoryId: "",
					departmentId: "",
					paymentMethodId: "",
					payMessage: "",
					orderNo: "",
					amount: "",
					errorMessage: "",
					errorCode: "",
					receiveData: "",
					skNumb: "",
					isFrom: "",
					createTime: "",
					remoteIp: "",
					flag: "",
				},
				//验证规则
				rules: {
					userName: [
						{required: true, message: '请输入名称'}
					],
					userAge: [
						{pattern: /^[0-9]*$/, message: '年龄需为数字', trigger: 'blur'}
					],
					price: [
						{pattern: /^\d+(\.\d+)?$/, message: '价格需为数字', trigger: 'blur'}
					]
				}
			}
		},
		mounted() {

		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this;
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if(valid){
						this.isSaveing = true;
						var res = await paymentAPI.paymentHistory.save.post(this.form);
						this.isSaveing = false;
						if(res.code === 2000){
							this.$emit('success', this.form, this.mode);
							this.visible = false;
							this.$message.success(res.message);
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				});
			},
			//表单注入数据
			setData(data){
				this.form.paymentHistoryId = data.paymentHistoryId;
				this.form.departmentId = data.departmentId;
				this.form.paymentMethodId = data.paymentMethodId;
				this.form.payMessage = data.payMessage;
				this.form.orderNo = data.orderNo;
				this.form.amount = data.amount;
				this.form.errorMessage = data.errorMessage;
				this.form.errorCode = data.errorCode;
				this.form.receiveData = data.receiveData;
				this.form.skNumb = data.skNumb;
				this.form.isFrom = data.isFrom;
				this.form.createTime = data.createTime;
				this.form.remoteIp = data.remoteIp;
				this.form.flag = data.flag;
			}
		}
	}
</script>
<style>
</style>
